#include "stdafx.h"
#include "Model.h"


CModel::CModel()
{

}

CModel::~CModel()
{

}

void CModel::AddMesh(CMesh* pMesh, D3DXMATRIX* pMatrix)
{
	std::vector<CMesh*>::iterator iter = std::find(mMeshs.begin(), mMeshs.end(), pMesh);
	if( iter == mMeshs.end() )
	{
		if( pMatrix == NULL )
		{
			D3DXMATRIX m;
			D3DXMatrixIdentity(&m);
			mMatrixs.push_back(m);
		}
		mMeshs.push_back(pMesh);
		pMesh->AddRefCount();
	}
}

void CModel::RemoveMesh(CMesh* pMesh)
{
	std::vector<CMesh*>::iterator iter = std::find(mMeshs.begin(), mMeshs.end(), pMesh);
	if (iter != mMeshs.end())
	{
		mMeshs.erase(iter);
		Safe_Release((*iter));
	}
}

void CModel::AddTexture(CTexture* pTexture)
{
	std::vector<CTexture*>::iterator iter = std::find(mTextures.begin(), mTextures.end(), pTexture);
	if (iter == mTextures.end())
	{
		mTextures.push_back(pTexture);
	}
}

void CModel::RemoveTexture(CTexture* pTexture)
{
	std::vector<CTexture*>::iterator iter = std::find(mTextures.begin(), mTextures.end(), pTexture);
	if (iter != mTextures.end())
	{
		mTextures.erase(iter);
		Safe_Release((*iter));
	}
}


